import { ApiCall } from "tsrpc";
import { ReqRoomList, ResRoomList } from "../../../tsrpc/shared/protocols/hall/PtlRoomList";
import { hs } from "../../../HallServiceEntra";
import { RoomInfo } from "../../../tsrpc/shared/types/RoomInfo";

export default async function (call: ApiCall<ReqRoomList, ResRoomList>) {

    if (!call.req.__ssoToken) {
        call.error("需要提供sso", {code:"INVALID_SSO"});
        return;
    }
    const ret = await hs.HallModel.hcAccount.callApi("ParseSSO", {
        sso: call.req.__ssoToken
    })
    if (!ret.isSucc) {
        call.error("无效的用户sso", {code:"INVALID_SSO"});
        return
    }

    // TODO
    let allRoomList:Array<RoomInfo> = []
    for (let i = 0; i < hs.HallModel.roomServiceList.length; i++) {
        const ret = await hs.HallModel.roomServiceList[i].wsc.callApi("RoomList", {});
        if (ret.isSucc) {
            allRoomList = allRoomList.concat(ret.res.roomList);
        }
        
    }
    //所有服务器的所有房间
    call.succ({
        list: allRoomList
    })
}